package com.lhoverc.controller.user;

import com.lhoverc.pojo.Result;
import com.lhoverc.pojo.VO.CommentVO;
import com.lhoverc.pojo.VO.PostVO;
import com.lhoverc.pojo.entity.CommentEntity;
import com.lhoverc.pojo.entity.LikeEntity;
import com.lhoverc.pojo.entity.PostEntity;
import com.lhoverc.service.post.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-05-03
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("/user/forum")
public class PostController {
    @Autowired
    private PostService postService;

    /**
     * 获取post
     * @return
     */
    @GetMapping("/getPosts")
    public Result getPosts(){
        List<PostVO> postVOList = postService.getPosts();
        return Result.success(postVOList);
    }

    /**
     * 获取帖子的评论
     * @param id
     * @return
     */
    @GetMapping("/getComments/{id}")
    public Result getComments(@PathVariable int id){
        List<CommentVO> commentVOList = postService.getComments(id);
        return Result.success(commentVOList);
    }

    /**
     * 添加评论
     * @param commentEntity
     * @return
     */
    @PostMapping("/addComment")
    public Result addComment(@RequestBody CommentEntity commentEntity){
        postService.addComment(commentEntity);
        return Result.success();
    }

    /**
     * 添加帖子
     * @param postEntity
     * @return
     */
    @PostMapping("/addPost")
    public Result addPost(@RequestBody PostEntity postEntity){
        postService.addPost(postEntity);
        return Result.success();
    }

    /**
     * 取消点赞
     * @param likeEntity
     * @return
     */
    @PostMapping("/deleteLike")
    public Result deleteLike(@RequestBody LikeEntity likeEntity){
        postService.deleteLike(likeEntity);
        return Result.success();
    }

    /**
     * 取消点赞
     * @param likeEntity
     * @return
     */
    @PostMapping("/addLike")
    public Result addLike(@RequestBody LikeEntity likeEntity){
        postService.addLike(likeEntity);
        return Result.success();
    }

    /**
     * 获取点赞的帖子id
     * @param likeEntity
     * @return
     */
    @PostMapping("/getLikes")
    public Result getLikes(@RequestBody LikeEntity likeEntity){
        List<Integer> postIdList = postService.getLikes(likeEntity);
        return Result.success(postIdList);
    }
}
